﻿using System;
using System.Collections.Generic;
using System.Text;
using MapReduce.Comm;

namespace MapReduce.Utils
{
    public static class StatusPageBuilder
    {
        public static String GetStatusHtml()
        {
            StringBuilder buf = new StringBuilder();
            buf.Append("<html>");
            buf.Append("<head>");
            buf.Append("<title>MapReduce.Net status</title>");
            buf.Append("</head>");
            buf.Append("<body>");


            buf.Append("<H1>Slave Status</H1><hr/>");
            buf.Append(GetStat(SlaveManager.Error));
            buf.Append(GetStat(SlaveManager.Buzy));
            buf.Append(GetStat(SlaveManager.Free));


            buf.Append("</body>");
            buf.Append("</html>");

            return buf.ToString();
        }

        private static StringBuilder GetStat(SortedList<String, String> pList)
        {
            StringBuilder buf = new StringBuilder();
            for (int i = 0; i < pList.Count; i++)
            {
                String address = pList.Keys[i];
                buf.Append("<h2>" + address).Append("<span style='color:blue;'>").Append(pList[address] + "</span></h2>");
                buf.Append("<br/><br/>");
                buf.Append(Logger.GetStatus(address));
                buf.Append("<hr/>");
            }
            return buf;
        }
    }
}
